import java.util.Currency;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2023-01-15
 * Time: 10:55
 */

    public class BinarySearchTree {
    static class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }

    public TreeNode root = null;

    /**
     * 查找二叉搜索树中指定的val值
     *
     * @param val
     * @return
     */
    public TreeNode find(int val) {
        TreeNode cur = root;
        while (cur != null) {
            if (cur.val == val) {
                return cur;
            } else if (cur.val < val) {
                cur = cur.right;
            } else {
                cur = cur.left;
            }
        }


        return null;

    }
    public void insert(int val){
        if(root==null){
           root=new TreeNode(val);
           return;
        }
        TreeNode cur=root;
        TreeNode parent=null;
        while(cur!=null){
            if(cur.val<val){
                parent=cur;
                cur=cur.right;
            }else{
                parent=cur;
                cur=cur.left;
            }
        }
           if(parent.val<val){
            parent.right=new TreeNode(val);
        }else{
            parent.left=new TreeNode(val);
        }
    }
    public void  inorder(TreeNode root){
    if(root==null){
        return;
    }
        inorder(root.left);
        System.out.println(root.val+"");
        inorder(root.right);

    }

}


